package com.tb.service.impl;

import com.tb.mapper.ClazzMapper;
import com.tb.mapper.CollegeMapper;
import com.tb.mapper.ProfessionMapper;
import com.tb.pojo.Clazz;
import com.tb.pojo.College;
import com.tb.pojo.Profession;
import com.tb.service.AllService;
import com.tb.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class InfoServiceImpl extends AllService implements InfoService {

    @Autowired
    protected CollegeMapper collegeMapper;

    @Autowired
    protected ClazzMapper clazzMapper;

    @Autowired
    protected ProfessionMapper professionMapper;



    @Override
    public List<College> findCollege() {
        return collegeMapper.findAll();
    }

    @Override
    public List<Profession> findProfession(int collegeId) {
        return professionMapper.findAll(collegeId);
    }

    @Override
    public List<Clazz> findClazz(int professionId) {
        return clazzMapper.findAll(professionId);
    }

    /**
     * 以我 专业--班级 的形式返回数据
     * @param collegeId 传入的学院的id
     * @return
     */
    @Override
    public Map<String, String> getProfessions(int collegeId) {
        Map<String, String> professions = new HashMap<>();
        List<Profession> professionList = findProfession(collegeId);
        for (Profession profession : professionList) {
            List<Clazz> clazzList =findClazz(Integer.parseInt(profession.getProfessionId()));
            for (Clazz clazz : clazzList) {
                professions.put(clazz.getClazzId(), profession.getProfession() + "--" + clazz.getClazz() + "班");
            }
        }
        return professions;
    }


}
